package com.base.study.activity;

import android.graphics.Color;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.base.commonlib.base.CBaseBarMvpActivity;
import com.base.commonlib.base.adapter.BaseAdapter;
import com.base.commonlib.base.adapter.BaseHolder;
import com.base.commonlib.bean.FieldInspectionEntity;
import com.base.commonlib.recy.utils.CustomDivider;
import com.base.commonlib.utils.RecycleGridDivider;
import com.base.commonlib.utils.ToastUtil;
import com.base.study.R;
import com.base.study.databinding.ActivityMyNavigationBinding;
import com.base.study.utils.MenuLeftSpaceItemDecoration;

import java.util.ArrayList;

import co.lujun.androidtagview.ColorFactory;

/**
 * Created by zw on 2020/2/13.
 * 我的导航
 */
@Route(path = "/curriculum/mynavigation")
public class MyNavigationActivity extends CBaseBarMvpActivity {

    private ActivityMyNavigationBinding mBinding;
    private BaseAdapter<String> mAdapter;
    private BaseAdapter<String> mSafeAdapter;
    private BaseAdapter<String> mWorkAdapter;
    ArrayList<String> tents = new ArrayList<>();
    ArrayList<String> safeTents = new ArrayList<>();
    ArrayList<String> workTents = new ArrayList<>();

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_my_navigation;
    }

    @Override
    protected void init() {
        super.init();
        mBinding = (ActivityMyNavigationBinding) mRootBinding;
    }

    @Override
    protected void start() {
        mBinding.icClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });



        mBinding.myNaEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });


        tents.add("安全生产");
        tents.add("垃圾分类");
        tents.add("城市管理");
        tents.add("市容环境");
        tents.add("疫情防疫");
        tents.add("门前三包");



        safeTents.add("危化作业");
        safeTents.add("电工作业");
        safeTents.add("烟花炮竹");
        safeTents.add("高处作业");
        safeTents.add("金属非矿山");
        safeTents.add("制冷与空调");
        safeTents.add("金属焊接");


        workTents.add("危化作业");
        workTents.add("电工作业");
        workTents.add("烟花炮竹");
        workTents.add("高处作业");
        workTents.add("金属非矿山");
        safeTents.add("制冷与空调");
        workTents.add("金属焊接");


        edit();


        safe();


        work();


    }


    private void edit(){
        mAdapter = new BaseAdapter<String>(tents,mContext) {
            @Override
            public void convert(BaseHolder holder, String s, boolean isHeader, boolean isBottom) {
                TextView tv_edit_lables = holder.getView(R.id.tv_edit_lables);
                tv_edit_lables.setText(s);
            }
        };
        mAdapter.putNormalType(R.layout.item_labels);
        mBinding.rv.setLayoutManager(new GridLayoutManager(mContext,4));
        mBinding.rv.setAdapter(mAdapter);
        mBinding.rv.addItemDecoration(new RecycleGridDivider());

        mAdapter.notifyDataSetChanged();

        mAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseHolder holder, int dataPosition, boolean isHeader, boolean isBottom) {
                ToastUtil.show("FFF"+dataPosition);
//                String s = tents.get(dataPosition);
//                safeTents.add(s);
//                mSafeAdapter.notifyDataSetChanged();
//                tents.remove(dataPosition);
//                mAdapter.notifyDataSetChanged();
            }
        });
    }

    private void safe(){
        mSafeAdapter = new BaseAdapter<String>(safeTents,mContext) {
            @Override
            public void convert(BaseHolder holder, String s, boolean isHeader, boolean isBottom) {
                TextView tv_safe_lables = holder.getView(R.id.tv_safe_lables);
                tv_safe_lables.setText(s);
            }
        };
        mSafeAdapter.putNormalType(R.layout.item_add_labels);
        mBinding.rvSafetySh.setLayoutManager(new GridLayoutManager(mContext,4));
        mBinding.rvSafetySh.setAdapter(mSafeAdapter);
        mBinding.rvSafetySh.addItemDecoration(new RecycleGridDivider());
        mSafeAdapter.notifyDataSetChanged();


        mSafeAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseHolder holder, int dataPosition, boolean isHeader, boolean isBottom) {
                String s = safeTents.get(dataPosition);
                tents.add(s);
                mAdapter.notifyDataSetChanged();
                safeTents.remove(dataPosition);
                mSafeAdapter.notifyDataSetChanged();
            }
        });
    }




    private void work(){
        mWorkAdapter = new BaseAdapter<String>(workTents,mContext) {
            @Override
            public void convert(BaseHolder holder, String s, boolean isHeader, boolean isBottom) {
                TextView tv_safe_lables = holder.getView(R.id.tv_safe_lables);
                tv_safe_lables.setText(s);
            }
        };
        mWorkAdapter.putNormalType(R.layout.item_add_labels);
        mBinding.rvNaWork.setLayoutManager(new GridLayoutManager(mContext,4));
        mBinding.rvNaWork.setAdapter(mWorkAdapter);
        mBinding.rvNaWork.addItemDecoration(new RecycleGridDivider());
        mWorkAdapter.notifyDataSetChanged();


        mWorkAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseHolder holder, int dataPosition, boolean isHeader, boolean isBottom) {
                String s = safeTents.get(dataPosition);
                tents.add(s);
                mAdapter.notifyDataSetChanged();
                workTents.remove(dataPosition);
                mWorkAdapter.notifyDataSetChanged();
            }
        });
    }
}
